package com.tucc.hello.leetcode.no1_400.no1_200.no21_40.no38;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        for(int i = 1;i < 10;i ++) {
            System.out.println(solution.countAndSay(i));
        }
    }

    public String countAndSay(int n) {
        if(n == 1) {
            return "1";
        }
        String str = countAndSay(n - 1);
        int c = 1;
        int curNum = str.charAt(0);
        StringBuilder stringBuilder = new StringBuilder();
        for(int i = 1;i < str.length();i ++){
            if(str.charAt(i) == curNum){
                c ++;
            }
            else{
                stringBuilder.append(c).append(curNum  - '0');
                curNum = str.charAt(i);
                c = 1;
            }
        }
        stringBuilder.append(c).append(curNum  - '0');
        return stringBuilder.toString();
    }


}
